package b;

import org.junit.Test;

import java.util.*;

public class 字母异位词 {
    public List<List<String>> 字母异位词(String[] ss) {
        int n = ss.length;
        String[] tempstrs = new String[n];
        Map<String, List<String>> map = new HashMap<>();

        for(int i = 0; i < n; i++){
            char[] chars = ss[i].toCharArray();
            Arrays.sort(chars);
            String key = String.valueOf(chars);
            //
            //初始化new,保证有List
            if (!map.containsKey(key)) map.put(key, new ArrayList<>());
            //
            map.get(key).add(ss[i]);
        }

        //奇葩用法，手撕时自己改写↓
        return new ArrayList<>(map.values());
    }
    
}
